package main

import (
	"time"
	"yundian/internel/app/helper"
	"yundian/internel/app/logic"
	"yundian/internel/pkg/dbs"
	"yundian/internel/pkg/dingo"
)

func main()  {
	dingo.InitViper("./configs/adm.yaml")
	dbs.NewMysqlComponent().Step()

	now := time.Now()
	startDay := now.AddDate(0, 0, -30).Format("2006-01-02")
	endDay := now.AddDate(0, 0, -20).Format("2006-01-02")
	days := helper.GetDayRangeTime(startDay, endDay)
	//log.Println(days)
	logic.NewTaskStatisticsUserLogic().StatisticsByTypeByHaveOrders(days)


	//var dateList []string
	//dateStr := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
	//dateList = append(dateList, dateStr)
	//logic.NewTaskStatisticsLogic().StatisticsByDateStr(dateList) // 中曼整体数据

	//now := time.Now()
	//startDay := now.AddDate(0, 0, -20).Format("2006-01-02")
	//endDay := now.AddDate(0, 0, -1).Format("2006-01-02")
	//log.Println(startDay, endDay)
	//days := helper.GetDayRangeTime(startDay, endDay)
	//log.Println(days)
	//logic.NewTaskStatisticsUserLogic().StatisticsByTypeByHaveOrders(days)


	//for i := 1; i <= 100; i ++ {
	//	var sn, mac string
	//	var newsn int
	//	if i >= 1 && i < 10 {
	//		sn = "0400" + fmt.Sprintf("%d", i)
	//		newsn = 4000 + i
	//		mac = "29:0E:03:60:40:0" + fmt.Sprintf("%d", i)
	//	} else if i >= 10 && i < 100 {
	//		sn = "040" + fmt.Sprintf("%d", i)
	//		newsn = 4000 + i
	//		mac = "29:0E:03:60:40:" + fmt.Sprintf("%d", i)
	//	} else if i == 100 {
	//		sn = "04100"
	//		newsn = 4100
	//		mac = "29:0E:03:60:41:00"
	//	}
	//	deviceSn := "220520ZM" + sn
	//	log.Println(newsn, deviceSn, mac)
	//	//sql := "INSERT INTO `zhongman`.`devices`(`device_sn`, `pre_sn`, `device_type_id`, `device_type_name`, `pwd_index`, `pwd_secret_key`, `pwd_decode_type`, `state`, `shared_mode`, `fee_mode`, `use_count`, `place_id`, `place_name`, `agent_user_id`, `agent_user_name`, `deploy_at`, `create_at`, `update_at`, `sn`, `url`, `domain_url`, `bluetooth_mac`, `room`, `prod_type`) " +
	//	//	"VALUES ('220520ZM04000', '220520ZM', 10, '免押密码线', 1, 'THLM10', 'GZXJ_510', 1, 'pcl', 1, 0, 0, '', 1, '网站创建者', 0, 1653041641, 1653041641, 4000, 0, 'https://blue.chinaman.ink/pcl/10082/dev/', '29:0E:03:60:40:00', '', 2);"
	//
	//	sql := "INSERT INTO `zhongman`.`devices`(`device_sn`, `pre_sn`, `device_type_id`, `device_type_name`, `pwd_index`, `pwd_secret_key`, `pwd_decode_type`, `state`, `shared_mode`, `fee_mode`, `use_count`, `place_id`, `place_name`, `agent_user_id`, `agent_user_name`, `deploy_at`, `create_at`, `update_at`, `sn`, `url`, `domain_url`, `bluetooth_mac`, `room`, `prod_type`) " +
	//		"VALUES (?, '220520ZM', 10, '免押密码线', 1, 'THLM10', 'GZXJ_510', 1, 'pcl', 1, 0, 0, '', 1, '网站创建者', 0, 1653041641, 1653041641, ?, 0, 'https://blue.chinaman.ink/pcl/10082/dev/', ? , '', 2);"
	//
	//	db := global.Orm.Table("devices").Exec(sql, deviceSn, sn, mac)
	//	if db.Error == nil {
	//		log.Println("执行成功", i)
	//	}
	//}





	//logic.NewTaskStatisticsLogic().StatisticsByType("day", "2021-06-02")
	//days := GetDayTime("2022-02-11", "2022-02-20")
	//log.Println(days)
	//logic.NewTaskStatisticsUserLogic().StatisticsByTypeByHaveOrders(days)
	//str := "2021-05-31"
	//newStr := strings.Split(str, "-")
	//lastStr := strings.Join(newStr, "")
	//log.Println(lastStr)


	//days := GetDayTime("2021-05-31", "2022-02-07")
	//for _,d := range days {
	//	//log.Println(d)
	//	logic.NewTaskStatisticsLogic().StatisticsByType("day", d)
	//}


	//now := time.Now()
	//startDay := now.AddDate(0, -3, -now.Day()).Format("2006-01-02")
	//endDay := now.AddDate(0, 0, -2).Format("2006-01-02")
	//log.Println(startDay, endDay)
	//days := helper.GetDayRangeTime(startDay, endDay)
	//for _,d := range days {
	//	log.Println(d)
	//	//logic.NewTaskStatisticsLogic().StatisticsByType("day", d)
	//}
	//helper.GetDayRangeTime()


	// 用户
	//logic.NewTaskStatisticsUserLogic().StatisticsByTypeByAdd("2021-11-16")
	//logic.NewTaskStatisticsUserLogic().StatisticsByTypeByUpdate("2021-11-16")
	//logic.NewTaskStatisticsUserLogic().StatisticsByTypeByHaveOrders("2021-11-17")
	//logic.NewTaskStatisticsUserLogic().StatisticsByTypeByNoHaveOrders("2021-11-17")
	//log.Println(244/4)
	//now := time.Now()
	//startDay := now.AddDate(0, -1, -now.Day()).Format("2006-01-02")
	//endDay := now.AddDate(0, 0, -1).Format("2006-01-02")
	//days := helper.GetDayRangeTime(startDay, endDay)
	//for _,d := range days {
	//	logic.NewTaskStatisticsUserLogic().StatisticsByTypeByAdd("day", d)
	//}
	//startDay := now.AddDate(0, -1, -now.Day()).Format("2006-01-02")
	//endDay := now.AddDate(0, 0, -2).Format("2006-01-02")
	//startDay := now.AddDate(0, 0, -11).Format("2006-01-02")
	//endDay := now.AddDate(0, 0, -7).Format("2006-01-02")
	//log.Println(startDay, endDay)
	//days := helper.GetDayRangeTime(startDay, endDay)
	//log.Println(days)
	//
	//startDay1 := now.AddDate(0, 0, -6).Format("2006-01-02")
	//endDay1 := now.AddDate(0, 0, -2).Format("2006-01-02")
	//log.Println(startDay1, endDay1)
	//days1 := helper.GetDayRangeTime(startDay1, endDay1)
	//log.Println(days1)

	//for _,d := range days {
	//	//log.Println(d)
	//	logic.NewTaskStatisticsLogic().StatisticsByType("day", d)
	//}

	//var ids []int
	//for i := 1; i <= 8000000; i++ {
	//	ids = append(ids, i)
	//}
	//log.Println(ids, len(ids))
}


func GetDayTime(startTime, stopTime string) (args []string) {
	tm1, _ := time.Parse("2006-01-02", startTime)
	tm2, _ := time.Parse("2006-01-02", stopTime)
	sInt := tm1.Unix()
	eInt := tm2.Unix()
	for {
		sInt += 86400
		st := time.Unix(sInt, 0).Format("2006-01-02")
		args = append(args,st)
		if sInt > eInt {
			return
		}
	}
}